<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<head>
    <title>register</title>
    <meta http-equiv="Content-Type" charset="UTF-8">
    <link rel="stylesheet" href="./static/css/font.css">
    <link rel="stylesheet" href="./static/css/xadmin.css">
    <link rel="stylesheet" href="./static/css/snow.css">
    <link rel="stylesheet" href="./static/css/style.css">
    <link rel="stylesheet" href="./static/css/font-awesome.min.css">
<%--    <script src="./static/js/jquery.min.js" type="text/javascript"></script>--%>
    <script src="/static/js/jquery.min.js" type="text/javascript"></script>
    <script src="./static/lib/layui/layui.js" type="text/javascript"></script>
    <script src="./static/js/xadmin.js" type="text/javascript"></script>
</head>
<body>
<div class="snow-container">
    <div class="snow foreground"></div>
    <div class="snow foreground layered"></div>
    <div class="snow middleground"></div>
    <div class="snow middleground layered"></div>
    <div class="snow background"></div>
    <div class="snow background layered"></div>
</div>

<div class="top-buttons-agileinfo">
	<a href="/login" class="active">登 入</a><a href="/register" >注 册</a>
</div>
<h1>用户管理系统注册</h1>
<div class="main-agileits" id="registerApp">
    <!--form-stars-here-->
    <div class="form-w3-agile">
        <h2 class="sub-agileits-w3layouts">注 册</h2>
        <form action="#" method="post">
            <input type="text" name="username" id="username" placeholder="username" required=""/>
            <input type="password" name="password" id="password" placeholder="password" required=""/>
            <input type="password" name="password" id="confirmPassword" placeholder="confirm password" required=""/>
            <button type="button" class="layui-btn layui-btn-lg layui-btn-normal" onclick="register()">注 册</button>
        </form>
    </div>
</div>
<!--//form-ends-here-->
<!-- copyright -->
<div class="copyright w3-agile">
    <p> © 2017 Internship Sign In & Sign Up Form . All rights reserved | Design by <a
            href="https://shop585798004.taobao.com/" target="_blank">前端ui</a></p>
</div>
<script>

</script>
</body>
<script>

    function register() {
        var username = $("#username").val();
        var password = $("#password").val();
        var confirmPassword = $("#confirmPassword").val();
        if (confirmPassword != password){
            layer.alert("密码不正确,请重新输入",{icon:5},function () {
                location.reload();
            });
        }else {
            $.ajax({
                url:"../user/register",
                type:"POST",
                dataType:"json",
                data:{
                    username:username,
                    password:password
                },
                success:function (data) {
                    console.log("进入");
                    if (data.code == 500){
                        layer.alert(data.message,{icon:5},function () {
                            location.reload();
                        })
                    }
                    if (data.code == 200){
                        layer.alert(data.message,{icon:6},function () {
                            location.href = "../login";
                        })
                    }
                },
                error:function () {
                    alert("服务器丢了");
                }
            });
        }

    }
</script>
</html>